package com.trkj.dao.jpa;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.trkj.pojos.LmbCousumablePurchase;
import com.trkj.pojos.YzrPurchOrder;

public interface LmbCousumablePurchaseDAO extends CrudRepository<LmbCousumablePurchase, String> {
    public List<LmbCousumablePurchase> findByCpStatus(String a);
    
    public List<LmbCousumablePurchase> findByCpId(String cpid);
    
    @Query("select  c from LmbCousumablePurchase c ,LmbMaterialAcceptance m WHERE m.matResult = ?1 and c.cpId = m.matCpId")
    public List<LmbCousumablePurchase> findResult(String result);
    
    @Query("select max(c.cpId) from LmbCousumablePurchase c where c.cpId like ?1%")
    public String findMaxID(String a);
    
    @Query("select c from LmbCousumablePurchase c where c.cpRsStatus like ?1%")
    public List<LmbCousumablePurchase> findCousPurchaseByCpRsStatus(String cpRsStatus,Pageable pageable);
    
    @Query("select count(*) from LmbCousumablePurchase c where c.cpRsStatus like ?1%")
    public long countCousPurchaseByCpRsStatus(String cpRsStatus);
    
    @Query("select c from LmbCousumablePurchase c where c.cpStatus like ?1%")
    public List<LmbCousumablePurchase> findCousPurchaseByCpStatus(String cpStatus,Pageable pageable);

    @Query("select count(*) from LmbCousumablePurchase c where c.cpStatus like ?1%")
    public long countCousPurchaseByCpStatus(String cpStatus);
    
    @Query("select c from LmbCousumablePurchase c where c.cpId like ?1%")
    public List<LmbCousumablePurchase> findCousPurchaseByCpId(String cpId,Pageable pageable);
    
    @Query("select count(*) from LmbCousumablePurchase c where c.cpId like ?1%")
    public long countCousPurchaseByCpId(String cpId);
    
    // 查找出‘未验收’and‘未入库’的采购订单
 	@Query("select c from LmbCousumablePurchase c where c.cpStatus='未验收' and c.cpRsStatus='未入库' order by c.cpId desc")
 	public List<LmbCousumablePurchase> findAllCouPurByNoCheck(Pageable pageable);
 	
 	// 查找出‘未验收’and‘未入库’的采购订单
  	@Query("select count(*) from LmbCousumablePurchase c where c.cpStatus='未验收' and c.cpRsStatus='未入库'")
  	public long countAllCouPurByNoCheck();
  	
  	//根据交货期日的时间段查询
  	@Query("select c from LmbCousumablePurchase c where c.cpTime between ?1 and ?2 order by c.cpId desc")
  	public List<LmbCousumablePurchase> findOrderByCiGouDate(Date startDate,Date endDate, Pageable pageable);
  	
  	@Query("select count(*) from LmbCousumablePurchase c where c.cpTime between ?1 and ?2")
  	public long countOrderByByCiGouDate(Date startDate,Date endDate);

  	@Query("select c from LmbCousumablePurchase c where c.cpBuyer =?1 order by c.cpId desc")
  	public List<LmbCousumablePurchase> findOrderByBuyer(BigDecimal cpBuyer,Pageable pageable);
  	
	@Query("select count(*) from LmbCousumablePurchase c where c.cpBuyer =?1")
  	public long countOrderByBuyer(BigDecimal cpBuyer);
}
